package domain

type MethodInfo struct {
	Struct      *StructInfo `json:"-"`
	LineNO      int
	Name        string
	Arguments   []*ArgumentInfo
	Annotations []*AnnotationInfo
	Returns     []*ArgumentInfo
}

func NewMethodInfo() *MethodInfo {
	it := new(MethodInfo)
	it.Arguments = []*ArgumentInfo{}
	it.Annotations = []*AnnotationInfo{}
	it.Returns = []*ArgumentInfo{}
	return it
}

func (me *MethodInfo) AppendArgument(name string, dataType string) {
	it := NewArgumentInfo()
	it.Method = me
	it.Name = name
	it.DataType = dataType
	me.Arguments = append(me.Arguments, it)
}

func (me *MethodInfo) AppendNamedReturn(name string, dataType string) {
	it := NewArgumentInfo()
	it.Method = me
	it.Name = name
	it.DataType = dataType
	me.Returns = append(me.Returns, it)
}

func (me *MethodInfo) AppendUnnamedReturn(dataType string) {
	me.AppendNamedReturn("", dataType)
}

func (me *MethodInfo) AppendAnnotation(ant *AnnotationInfo) {
	me.Annotations = append(me.Annotations, ant)
}

func (me *MethodInfo) Clone() interface{} {
	it := new(MethodInfo)
	it.Struct = me.Struct
	it.LineNO = me.LineNO
	it.Name = me.Name

	it.Arguments = make([]*ArgumentInfo, len(me.Arguments))
	for i, v := range me.Arguments {
		it.Arguments[i] = v.Clone().(*ArgumentInfo)
		it.Arguments[i].Method = it
	}

	it.Annotations = make([]*AnnotationInfo, len(me.Arguments))
	for i, v := range me.Annotations {
		it.Annotations[i] = v.Clone().(*AnnotationInfo)
	}

	it.Returns = make([]*ArgumentInfo, len(me.Returns))
	for i, v := range me.Returns {
		it.Returns[i] = v.Clone().(*ArgumentInfo)
		it.Returns[i].Method = it
	}

	return it
}
